package edu.spbu.eclipse.adressbook.zhukovazalog;
/** @author Anna Zhukova
 * @author Leonid Zalog
 *
 */
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.JRadioButton;

public class Surface {
		
	private int sortFlag = 1;

	private JFrame frame = null;

	private JPanel panel = null;

	private JPanel windowPanel = null;

	private JPanel panelWithButtons = null;

	private JPanel dialogPanel = null;

	private JPanel addDialogPanel = null;

	private JWindow window = null;

	private final Vector colHeaders = new Vector();

	public static Vector<Vector<LinkedList<String>>> data = new Vector<Vector<LinkedList<String>>>(); // @jve:decl-index=0:

	public static Vector selectedData = new Vector();

	private static final long serialVersionUID = 1L;

	private JButton addButton = null;

	private JButton delButton = null;

	private JScrollPane jScrollPane = null;

	private JTable jTable = null;

	private JTextField fnameTextField = null;

	private JTextField lnameTextField = null;

	private JTextField mnumberTextField = null;

	private JTextField hnumberTextField = null;

	private JTextField emailTextField = null;

	private JTextField addMnumberTextField = null;

	private JTextField addHnumberTextField = null;

	private JButton okButton = null;

	private JTextField addEmailTextField = null;

	private JButton saveButton = null;

	private JButton addInfoButton = null;

	private MenuBar mb = null;

	private JRadioButton jRButton = null;

	private Model mod = null;

	private JRadioButton jMobNumButton = null;

	private JRadioButton jHomNumButton = null;

	private JRadioButton jEmailButton = null;

	private JRadioButton jRButtonSortByFName = null;

	private JRadioButton jRButtonSortByLName = null;

	private JPanel panelWithRadioButtons = null;

	private JButton searchButton = null;

	private JDialog jdialog = null;

	JDialog addJDialog = null;

	private JDialog searchDialog = null;

	private JPanel searchDialogPanel = null;

	private JTextField searchTextField = null;

	private boolean MobNumNeed = false;

	private boolean HomNumNeed = false;

	private boolean EmailNeed = false;

	private JRadioButton jRButtonSearchByFName = null;

	private JRadioButton jRButtonSearchByLName = null;

	private CaretListener crlst = null;

	private JDialog jViewContactDialog = null;

	private JPanel jViewContactPanel = null;

	private LinkedList mnumberToSave = null;

	private LinkedList hnumberToSave = null;

	private LinkedList emailToSave = null;

	/**
	 * This is the default constructor
	 */
	public Surface() {
		getFrame();		
		Model mod = new Model();
		this.mod = mod;
		mnumberToSave = new LinkedList();
		hnumberToSave = new LinkedList();
		emailToSave = new LinkedList();
	}
	
	/**
	 * This method initializes jReButton
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRButton() {
		if (jRButton == null) {
			jRButton = new JRadioButton("Table Is Editable");
			jRButton.setSelected(true);
			jRButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRButton.isSelected()) {
						getJTable().setEnabled(true);
						getDelButton().setEnabled(true);
					} else {
						getJTable().setEnabled(false);
						getDelButton().setEnabled(false);
					}
				}
			});

		}
		return jRButton;
	}

	/**
	 * This method initializes flag-button for mobile number
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJMobNumButton() {
		if (jMobNumButton == null) {
			jMobNumButton = new JRadioButton("Need to add mobile number");
			jMobNumButton.setSelected(false);
			jMobNumButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jMobNumButton.isSelected()) {
						MobNumNeed = true;
					} else {
						MobNumNeed = false;
					}
				}
			});
		}
		return jMobNumButton;
	}

	/**
	 * This method initializes flag-button for Home Number
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJHomNumButton() {
		if (jHomNumButton == null) {
			jHomNumButton = new JRadioButton("Need to add home number");
			jHomNumButton.setSelected(false);
			jHomNumButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jHomNumButton.isSelected()) {
						HomNumNeed = true;
					} else {
						HomNumNeed = false;
					}
				}
			});
		}
		return jHomNumButton;
	}

	/**
	 * This method initializes flag-button for email
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJEmailButton() {
		if (jEmailButton == null) {
			jEmailButton = new JRadioButton("Need to add email");
			jEmailButton.setSelected(false);
			jEmailButton.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jEmailButton.isSelected()) {
						EmailNeed = true;
					} else {
						EmailNeed = false;
					}
				}
			});
		}
		return jEmailButton;
	}

	/**
	 * This method initializes frame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getFrame() {
		if (frame == null) {
			frame = new JFrame();
			frame.setSize(505, 570);
			frame.setMenuBar(getMB());
			frame.setContentPane(getPanel());
			frame.setVisible(true);
			frame.setDefaultCloseOperation(frame.HIDE_ON_CLOSE);

		}
		return frame;
	}

	/**
	 * This method initializes window
	 * 
	 * @return javax.swing.JWindow
	 */
	private JWindow getWindow() {
		if (window == null) {
			window = new JWindow();
			window.setSize(150, 100);
			window.setLocation(getJDialog().getLocation().x + 50, getJDialog()
					.getLocation().y + 50);
			window.setContentPane(getWindowPanel());
			window.addMouseListener(new MouseListener() {
				public void mousePressed(MouseEvent e) {
					window.setVisible(false);
				}

				public void mouseReleased(MouseEvent e) {
				}

				public void mouseEntered(MouseEvent e) {
				}

				public void mouseExited(MouseEvent e) {
				}

				public void mouseClicked(MouseEvent e) {
				}
			});

		}
		return window;
	}

	/**
	 * This method initializes windowPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getWindowPanel() {
		if (windowPanel == null) {
			windowPanel = new JPanel();
			windowPanel.setBackground(Color.white);
			windowPanel.setLayout(new GridLayout(3, 1));
			windowPanel.add(new JLabel(""));
			windowPanel.add(new JLabel("          Nothing to Save "));
		}
		return windowPanel;
	}

	/**
	 * This method initializes mb
	 * 
	 * @return java.awt.MenuBar
	 */
	protected MenuBar getMB() {
		if (mb == null) {
			mb = new MenuBar();
			MenuItem read = new MenuItem("Read from file");
			read.addActionListener(new ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						mod.loadFromFile();
						sortData(sortFlag);
						frame.setContentPane(panel);
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			});
			MenuItem save = new MenuItem("Save to file");
			save.addActionListener(new ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						mod.saveToFile(data);
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			});
			Menu menu = new Menu("File");
			menu.add(read);
			menu.add(save);
			mb.add(menu);
			frame.setMenuBar(mb);
		}
		return mb;
	}

	/**
	 * This method initializes saveButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getSaveButton() {
		if (saveButton == null) {
			saveButton = new JButton("Save");
			saveButton.addActionListener(new ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if ((fnameTextField.getText().compareTo("") == 0)
							& (lnameTextField.getText().compareTo("") == 0)
							& (mnumberTextField.getText().compareTo("") == 0)
							& (hnumberTextField.getText().compareTo("") == 0)
							& (emailTextField.getText().compareTo("") == 0)) {
						getWindow().setVisible(true);
						return;
					}
					Vector inf = new Vector();
					LinkedList l = new LinkedList();
					l.add(fnameTextField.getText());
					inf.add(l);
					l = new LinkedList();
					l.add(lnameTextField.getText());
					inf.add(l);
					mnumberToSave.add(mnumberTextField.getText());
					inf.add(mnumberToSave);
					mnumberToSave = new LinkedList();
					hnumberToSave.add(hnumberTextField.getText());
					inf.add(hnumberToSave);
					hnumberToSave = new LinkedList();
					emailToSave.add(emailTextField.getText());
					inf.add(emailToSave);
					emailToSave = new LinkedList();
					data.add(inf);
					sortData(sortFlag);
					frame.setContentPane(panel);
					fnameTextField.setText("");
					lnameTextField.setText("");
					mnumberTextField.setText("");
					hnumberTextField.setText("");
					emailTextField.setText("");
					getJDialog().setVisible(false);
				}
			});
		}
		return saveButton;
	}

	/**
	 * This method initializes addInfoButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton addInfoButton() {
		if (addInfoButton == null) {
			addInfoButton = new JButton("addInfo");
			addInfoButton.addActionListener(new ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					addDialogPanel = null;
					getJDialog().setVisible(false);
					getAddJDialog().setContentPane(getAddDialogPanel());
					getAddJDialog().setVisible(true);

				}
			});
		}
		return addInfoButton;
	}

	/**
	 * This method initializes jDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getJDialog() {
		if (jdialog == null) {
			jdialog = new JDialog();
			jdialog.setSize(700, 400);
			jdialog.setContentPane(getDialogPanel());
			jdialog.setDefaultCloseOperation(jdialog.HIDE_ON_CLOSE);
		}
		return jdialog;
	}

	private JDialog getAddJDialog() {
		if (addJDialog == null) {
			addJDialog = new JDialog();
			addJDialog.setSize(500, 500);
			addJDialog.setContentPane(getAddDialogPanel());
			addJDialog.setDefaultCloseOperation(addJDialog.HIDE_ON_CLOSE);
		}
		return addJDialog;
	}

	/**
	 * This method initializes panelWithButtons
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelWithButtons() {
		if (panelWithButtons == null) {
			panelWithButtons = new JPanel();
			panelWithButtons.setLayout(new GridLayout(2, 1));
			JPanel panel1 = new JPanel();
			JPanel panel2 = new JPanel();
			panel1.add(getAddButton());
			panel1.add(getJRButton());
			panel1.add(getDelButton());
			panel2.add(getPanelWithRadioButtons());
			panelWithButtons.add(panel1);
			panelWithButtons.add(panel2);
		}
		return panelWithButtons;
	}

	/**
	 * This method initializes panelWithRadioButtons
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelWithRadioButtons() {
		if (panelWithRadioButtons == null) {
			panelWithRadioButtons = new JPanel();
			panelWithRadioButtons.setLayout(new GridLayout());
			ButtonGroup bg = new ButtonGroup();
			bg.add(getJRButtonSortByFName());
			bg.add(getJRButtonSortByLName());
			panelWithRadioButtons.add(getJRButtonSortByFName());
			panelWithRadioButtons.add(getJRButtonSortByLName());
		}
		return panelWithRadioButtons;
	}

	/**
	 * This method initializes jRButtonSortByFName
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRButtonSortByFName() {
		if (jRButtonSortByFName == null) {
			jRButtonSortByFName = new JRadioButton("Sort by First Name");
			jRButtonSortByFName.setSelected(false);
			jRButtonSortByFName
					.addItemListener(new java.awt.event.ItemListener() {
						public void itemStateChanged(java.awt.event.ItemEvent e) {
							if (jRButtonSortByFName.isSelected()) {
								sortFlag = 0;
								sortData(sortFlag);
								frame.setContentPane(panel);
							}
						}
					});

		}
		return jRButtonSortByFName;
	}

	/**
	 * This method initializes jRButtonSortByLName
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRButtonSortByLName() {
		if (jRButtonSortByLName == null) {
			jRButtonSortByLName = new JRadioButton("Sort by Last Name");
			jRButtonSortByLName.setSelected(true);
			jRButtonSortByLName
					.addItemListener(new java.awt.event.ItemListener() {
						public void itemStateChanged(java.awt.event.ItemEvent e) {
							if (jRButtonSortByLName.isSelected()) {
								sortFlag = 1;
								sortData(sortFlag);
								frame.setContentPane(panel);
							}
						}
					});
		}
		return jRButtonSortByLName;
	}

	/**
	 * This method initializes dialogPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getDialogPanel() {
		if (dialogPanel == null) {
			dialogPanel = new JPanel();
			dialogPanel.setLayout(new GridLayout(6, 3));
			fnameTextField = new JTextField(10);
			lnameTextField = new JTextField(10);
			mnumberTextField = new JTextField(10);
			hnumberTextField = new JTextField(10);
			emailTextField = new JTextField(10);
			dialogPanel.add(new JLabel("First Name: "));
			dialogPanel.add(fnameTextField);
			dialogPanel.add(new JLabel());
			dialogPanel.add(new JLabel("Last Name: "));
			dialogPanel.add(lnameTextField);
			dialogPanel.add(new JLabel());
			dialogPanel.add(new JLabel("Mobile Number: "));
			dialogPanel.add(mnumberTextField);
			dialogPanel.add(getJMobNumButton());
			dialogPanel.add(new JLabel("Home Number: "));
			dialogPanel.add(hnumberTextField);
			dialogPanel.add(getJHomNumButton());
			dialogPanel.add(new JLabel("E-mail: "));
			dialogPanel.add(emailTextField);
			dialogPanel.add(getJEmailButton());
			dialogPanel.add(getSaveButton());
			dialogPanel.add(new JLabel());
			dialogPanel.add(addInfoButton());

		}
		return dialogPanel;
	}

	/**
	 * This method initializes addDialogPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getAddDialogPanel() {
		if (addDialogPanel == null) {
			addDialogPanel = new JPanel();
			addDialogPanel.setLayout(new GridLayout(7, 1));
			addMnumberTextField = new JTextField(10);
			addHnumberTextField = new JTextField(10);
			addEmailTextField = new JTextField(10);
			if (MobNumNeed & (mnumberTextField.getText().compareTo("") != 0)) {
				addDialogPanel.add(new JLabel("Mobile Number: "));
				addDialogPanel.add(addMnumberTextField);
			} else {
				addDialogPanel.add(new JLabel());
				addDialogPanel.add(new JLabel());
			}
			if (HomNumNeed & (hnumberTextField.getText().compareTo("") != 0)) {
				addDialogPanel.add(new JLabel("Home Number: "));
				addDialogPanel.add(addHnumberTextField);

			} else {
				addDialogPanel.add(new JLabel());
				addDialogPanel.add(new JLabel());
			}
			if (EmailNeed & (emailTextField.getText().compareTo("") != 0)) {
				addDialogPanel.add(new JLabel("E-mail: "));
				addDialogPanel.add(addEmailTextField);
			} else {
				addDialogPanel.add(new JLabel());
				addDialogPanel.add(new JLabel());
			}

			addDialogPanel.add(getOkButton());

		}
		return addDialogPanel;
	}

	/**
	 * This method initializes panel
	 * 
	 * @return javax.swing.JPanel
	 */
	protected JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.fill = GridBagConstraints.SOUTH;
			gridBagConstraints2.gridy = 2;
			gridBagConstraints2.gridx = 0;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
			gridBagConstraints1.gridy = 1;
			gridBagConstraints1.weightx = 1.0;
			gridBagConstraints1.weighty = 1.0;
			gridBagConstraints1.gridx = 0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			panel.setSize(300, 200);
			panel.setLayout(new GridBagLayout());
			panel.add(getPanelWithButtons(), gridBagConstraints);
			panel.add(getJScrollPane(), gridBagConstraints1);
			panel.add(getSearchButton(), gridBagConstraints2);

		}
		return panel;
	}

	/**
	 * This method initializes colHeaders
	 * 
	 * @return void
	 */
	private void initializeColHeaders() {
		colHeaders.add(new String(" First name"));
		colHeaders.add(new String(" Last name"));
		colHeaders.add(new String(" Mobile number"));
		colHeaders.add(new String(" Home number"));
		colHeaders.add(new String(" E-mail"));

	}

	private void sortData(int sortFlag) {
		getJTable().clearSelection();
		switch (sortFlag) {
		case 0:
			Collections.sort(data, new Comparator() {
				public int compare(Object v1, Object v2) {
					return (((String) ((LinkedList) ((Vector) v1).get(0))
							.get(0))
							.compareTo((String) ((LinkedList) ((Vector) v2)
									.get(0)).get(0)));
				}
			});
			break;
		case 1:
			Collections.sort(data, new Comparator() {
				public int compare(Object v1, Object v2) {
					return (((String) ((LinkedList) ((Vector) v1).get(1))
							.get(0))
							.compareTo((String) ((LinkedList) ((Vector) v2)
									.get(1)).get(0)));
				}
			});
			break;
		}
	}

	/**
	 * This method initializes addButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getAddButton() {
		if (addButton == null) {
			addButton = new JButton();
			addButton.setText("New Contact");
			addButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getJDialog().setVisible(true);
				}
			});
		}
		return addButton;
	}

	/**
	 * This method initializes okButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("Ok");
			okButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (addMnumberTextField.getText().compareTo("") != 0) {
						mnumberToSave.add(addMnumberTextField.getText());
					}
					if (addHnumberTextField.getText().compareTo("") != 0) {
						hnumberToSave.add(addHnumberTextField.getText());
					}
					if (addEmailTextField.getText().compareTo("") != 0) {
						emailToSave.add(addEmailTextField.getText());
					}
					addMnumberTextField.setText("");
					addHnumberTextField.setText("");
					addEmailTextField.setText("");
					getJDialog().setVisible(true);
					getAddJDialog().setVisible(false);
				}
			});
		}
		return okButton;
	}

	/**
	 * This method initializes addButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getDelButton() {
		if (delButton == null) {
			delButton = new JButton();
			delButton.setText("Delete Contacts");
			delButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getJViewContactDialog().setVisible(false);
					int[] mas = jTable.getSelectedRows();
					if (mas.length > 0) {
						for (int i = mas.length - 1; i >= 0; i--) {
							data.remove(mas[i]);
						}
					}
					jTable.clearSelection();
					frame.setContentPane(panel);
				}
			});
		}
		return delButton;
	}

	/**
	 * This method initializes searchButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getSearchButton() {
		if (searchButton == null) {
			searchButton = new JButton("Search");
			searchButton.addActionListener(new ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getSearchTextField().setText("");
					getSearchDialog().setVisible(true);
				}
			});
		}
		return searchButton;
	}

	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getJTable() {
		if (jTable == null) {
			initializeColHeaders();
			jTable = new JTable(data, colHeaders);
			jTable.setColumnSelectionAllowed(false);
			jTable.setRowSelectionAllowed(true);
			jTable.addMouseListener(new MouseListener() {
				public void mouseExited(MouseEvent e) {
				}

				public void mouseEntered(MouseEvent e) {
				}

				public void mouseClicked(MouseEvent e) {
					int i = e.getY() / jTable.getRowHeight();
					getJViewContactPanel().removeAll();
					getJViewContactPanel().add(new JList((Vector) data.get(i)));
					getJViewContactDialog().setContentPane(
							getJViewContactPanel());
					getJViewContactDialog().setVisible(true);
				}

				public void mousePressed(MouseEvent e) {
				}

				public void mouseReleased(MouseEvent e) {
				}

			});
		}
		return jTable;
	}

	/**
	 * This method initializes searchDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getSearchDialog() {
		if (searchDialog == null) {
			searchDialog = new JDialog(getJDialog());
			searchDialog.setSize(new Dimension(357, 101));
			searchDialog.setContentPane(getSearchDialogPanel());
			searchDialog.setDefaultCloseOperation(searchDialog.HIDE_ON_CLOSE);
		}
		return searchDialog;
	}

	/**
	 * This method initializes searchDialogPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getSearchDialogPanel() {
		if (searchDialogPanel == null) {
			searchDialogPanel = new JPanel();
			searchDialogPanel.setLayout(new GridLayout(2, 1));
			JPanel panel = new JPanel();
			panel.setLayout(new FlowLayout());
			ButtonGroup bg = new ButtonGroup();
			bg.add(getJRButtonSearchByFName());
			bg.add(getJRButtonSearchByLName());
			panel.add(getJRButtonSearchByFName());
			panel.add(getJRButtonSearchByLName());
			searchDialogPanel.add(panel);
			searchDialogPanel.add(getSearchTextField());
		}
		return searchDialogPanel;
	}

	/**
	 * This method initializes searchTextField
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getSearchTextField() {
		if (searchTextField == null) {
			searchTextField = new JTextField();
			crlst = new CaretListener() {
				private boolean flag;

				private int beg, i;

				public void caretUpdate(CaretEvent e) {
					String str = searchTextField.getText();
					jTable.clearSelection();
					if (str.compareTo("") == 0)
						return;
					flag = false;
					beg = -1;
					for (i = 0; i < data.size(); i++) {
						Vector v = (Vector) data.get(i);
						String str1 = (String) ((LinkedList) v.get(sortFlag))
								.get(0);
						if (str1.startsWith(str)) {
							if (!flag) {
								flag = true;
								beg = i;
							}
						} else {
							if (flag)
								break;
						}
					}
					if (beg >= 0)
						jTable.setRowSelectionInterval(beg, i - 1);
				}
			};
			searchTextField.addCaretListener(crlst);
		}
		return searchTextField;
	}

	/**
	 * This method initializes jRButtonSearchByFName
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRButtonSearchByFName() {
		if (jRButtonSearchByFName == null) {
			jRButtonSearchByFName = new JRadioButton("Search by First Name");
			jRButtonSearchByFName.setSelected(sortFlag == 0);
			jRButtonSearchByFName
					.addItemListener(new java.awt.event.ItemListener() {
						public void itemStateChanged(java.awt.event.ItemEvent e) {
							if (jRButtonSearchByFName.isSelected()) {
								jRButtonSortByFName.setSelected(true);
								crlst.caretUpdate(null);
							}
						}
					});
		}
		return jRButtonSearchByFName;
	}

	/**
	 * This method initializes jRButtonSearchByLName
	 * 
	 * @return javax.swing.JRadioButton
	 */
	private JRadioButton getJRButtonSearchByLName() {
		if (jRButtonSearchByLName == null) {
			jRButtonSearchByLName = new JRadioButton("Search by Last Name");
			jRButtonSearchByLName.setSelected(sortFlag == 1);
			jRButtonSearchByLName
					.addItemListener(new java.awt.event.ItemListener() {
						public void itemStateChanged(java.awt.event.ItemEvent e) {
							if (jRButtonSearchByLName.isSelected()) {
								jRButtonSortByLName.setSelected(true);
								crlst.caretUpdate(null);
							}
						}
					});
		}
		return jRButtonSearchByLName;
	}

	/**
	 * This method initializes jViewContactDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getJViewContactDialog() {
		if (jViewContactDialog == null) {
			jViewContactDialog = new JDialog(getJDialog());
			jViewContactDialog.setSize(new Dimension(250, 150));
			jViewContactDialog.setContentPane(getJViewContactPanel());
			jViewContactDialog
					.setDefaultCloseOperation(jViewContactDialog.HIDE_ON_CLOSE);
		}
		return jViewContactDialog;
	}

	/**
	 * This method initializes jViewContactPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJViewContactPanel() {
		if (jViewContactPanel == null) {
			jViewContactPanel = new JPanel();
			jViewContactPanel.setLayout(new BorderLayout());
		}
		return jViewContactPanel;
	}

}
